package org.btik.light.server.platform.common.api.bean.common;

/**
 * @author lustre
 * @since 2023/6/13 18:36
 */
public class ResultFactory {
    private static final StatusResult<Void> SUCCESS = new StatusResult<>(true);

    private static final StatusResult<Void> FAILED = new StatusResult<>(false);


    public static <T> StatusResult<T> success() {
        return (StatusResult<T>) SUCCESS;
    }

    public static <T> StatusResult<T> success(T obj) {
        StatusResult<T> result = new StatusResult<>();
        result.setResult(obj);
        result.setSuccess(true);
        return result;
    }

    public static <T> StatusResult<T> failed(String statusCode, String message) {
        StatusResult<T> result = new StatusResult<>();
        result.setStatusCode(statusCode);
        result.setMsg(message);
        return result;
    }

    public static <T> StatusResult<T> failed(String statusCode) {
        return failed(statusCode, null);
    }

    public static <T> StatusResult<T> failed(Enum<?> statusCode, String message) {
        return failed(statusCode.name(), message);
    }

    public static <T> StatusResult<T> failed(Enum<?> statusCode) {
        return failed(statusCode, null);
    }

    public static <T> StatusResult<T> failed() {
        return (StatusResult<T>) FAILED;
    }

}
